<template>
<div class="bg-login">
  <div class="login-box">
    <h2>登陆界面</h2>

    <form action="">
      <div class="login-field">
        <input type="text" v-model="loginForm.username" placeholder="用户名">
      </div>
      <div class="login-field">
       <input type="password" v-model="loginForm.password" placeholder="密码">
      </div>
      <button @click.prevent="login">登录</button>  
    </form>

  </div>
  </div>
</template>

<script>
import {mapMutations} from 'vuex'

export default {
    data(){
        return{
            loginForm:{
                username:"",
                password:""
            }
        }
    },
    created(){
      
    },
    methods:{
        

        ...mapMutations(['$_setStorage']),
        login(){

                // let this = this;
            if (this.loginForm.username === "" || this.loginForm.password === "") {
              alert("账号或密码不能为空");
            } else {
              this.$axios({
                method: "post",
                url: "/login/signup",
                data: this.loginForm
              }).then(res => {
                // let Datee = {
                //     id:res.data.result.id,
                //     last_login_at:result.last_login_at
                // }
                // this.$axios.put('/admin/update',Datee)
                localStorage.setItem('name',this.loginForm.username);             
                this.$_setStorage({Authorization:res.data.token});
                localStorage.setItem('adminName',res.data.result.name)
                localStorage.setItem('adminId',res.data.result.id)
                localStorage.setItem('adminLastLoginAt',res.data.result.last_login_at)
                localStorage.setItem('role',res.data.result.role);
                // window.localStorage.setItem("adminpass",this.loginForm.password)
                this.$message({
                            type:"success",
                            message:"添加信息成功"
                        })
                this.$router.push('/index');
                // alert("登录成功")

              }).catch(error => {
                
                console.log(error.stack);
                alert("账号或密码错误");
              });

                    
                }
        }
    }
}
</script>

<style scoped="scoped">

body{
  width: 100%;
  margin: 0;
  padding: 0;


}
.bg-login{
  height: 100%;
  width: 100%;
	background:url('../../assets/login.jpg')  no-repeat center center;
  background-size: cover;
  /* 把背景扩展足够大 覆盖背景区域 */
}
.login-box{
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%,-50%);
	width: 400px;
	padding:40px;
  /* background:red; */
	background: rgba(0,0,0,.8);
	box-sizing: border-box;
	box-shadow: 0 15px  25px rgba(0,0,0,.5);
	border-radius: 10px;
}
.login-box h2{
	margin: 0 0 30px;
	padding: 0;
	text-align: center;
	color: #fff;
}
.login-box .login-field{
	position: relative;
}
.login-box .login-field  input{
	width: 100%;
	padding: 10px 0;
	font-size: 16px;
	color: #fff;
	margin-bottom: 30px;
	border: none;  
	border-bottom: 1px solid #fff;
	background: transparent;
}

.login-box button{
	background: transparent;
	border: none;
	color: #fff;
	background: #03a9f4;
	padding: 10px 20px;
	cursor: pointer;
	border-radius: 5px;
}


</style>